;;高亮
(use-package highlight-global
    :ensure nil
    :demand t
    :commands (highlight-frame-toggle)
    :quelpa (highlight-global :fetcher github :repo "glen-dai/highlight-global")
    :config
    (progn
    (setq-default highlight-faces
                    '(('hi-red-b . 0)
                    ('hi-aquamarine . 0)
                    ('hi-pink . 0)
                    ('hi-blue-b . 0))))
)

;;symbol-overlay 类似highlight-symbol
(use-package symbol-overlay
    :ensure t
    :defer t
    :config
    (define-key symbol-overlay-map (kbd "h") 'nil)
)

;;markdown
(use-package markdown-mode
    :ensure t
    :defer t
)

;;visual-regexp 可视化正则匹配
(use-package visual-regexp
    :ensure t
    :defer t
    :commands (vr/replace vr/query-replace)
)

(use-package visual-regexp-steroids
    :defer
    :commands (vr/select-replace vr/select-query-replace)
    :init
    (progn
        (define-key global-map (kbd "C-c C-a") 'vr/replace)
        (define-key global-map (kbd "C-c C-q") 'vr/query-replace))
)

;; 告诉你当前mode的一些说明/快捷键设置
(use-package discover-my-major
    :ensure t
    :defer t
    :init
)

;; 有道字典
(use-package youdao-dictionary
    :ensure t
    :defer t
    :commands (youdao-dictionary-search-at-point+)
    :init
    (global-set-key (kbd "C-c y") 'youdao-dictionary-search-at-point+)
)

;;批量修改名称
(use-package iedit
    :ensure t
    :init
    (setq iedit-toggle-key-default nil)
    :config
    (define-key iedit-mode-keymap (kbd "M-h") 'iedit-restrict-function)
    (define-key iedit-mode-keymap (kbd "M-i") 'iedit-restrict-current-line)
)

;; 多光标模式
(use-package evil-multiedit
    :ensure t
    :defer t
    :commands (evil-multiedit-default-keybinds)
    :init
    (evil-multiedit-default-keybinds)
)

;;标记块 函数在er/中
(use-package expand-region
    :ensure t
    :config
    (defadvice er/prepare-for-more-expansions-internal
        (around helm-ag/prepare-for-more-expansions-internal activate)
    ad-do-it
    (let ((new-msg (concat (car ad-return-value)
                            ", H to highlight in buffers"
                            ", / to search in project, "
                            "e iedit mode in functions"
                            "f to search in files, "
                            "b to search in opened buffers"))
            (new-bindings (cdr ad-return-value)))
        (cl-pushnew
        '("H" (lambda ()
                (interactive)
                (call-interactively
                'custom/highlight-dwim)))
        new-bindings)
        (cl-pushnew
        '("/" (lambda ()
                (interactive)
                (call-interactively
                'my/search-project-for-symbol-at-point)))
        new-bindings)
        (cl-pushnew
        '("e" (lambda ()
                (interactive)
                (call-interactively
                'evil-multiedit-match-all)))
        new-bindings)
        (cl-pushnew
        '("f" (lambda ()
                (interactive)
                (call-interactively
                'find-file)))
        new-bindings)
        (cl-pushnew
        '("b" (lambda ()
                (interactive)
                (call-interactively
                'consult-line)))
        new-bindings)
        (setq ad-return-value (cons new-msg new-bindings)))))

;; 快速run 代码
;; https://github.com/emacsorphanage/quickrun
(use-package quickrun
    :ensure t
    :commands (quickrun)
    :init
    (quickrun-add-command "c++/c1z"
    '((:command . "g++")
        (:exec . ("%c -std=c++1z %o -o %e %s"
                "%e %a"))
        (:remove . ("%e")))
    :default "c++")
    (quickrun-add-command "python"
    '((:command . "python3"))
    :default "python")
    (quickrun-add-command "lua"
    '((:command . "lua"))
    :default "lua")
)

;; 显示命令对应的快捷键
(use-package keycast
  :ensure t
  :commands (+toggle-keycast)
  :config
  (defun +toggle-keycast()
    (interactive)
    (if (member '("" keycast-mode-line " ") global-mode-string)
        (progn (setq global-mode-string (delete '("" keycast-mode-line " ") global-mode-string))
               (remove-hook 'pre-command-hook 'keycast--update)
               (message "Keycast OFF"))
      (add-to-list 'global-mode-string '("" keycast-mode-line " "))
      (add-hook 'pre-command-hook 'keycast--update t)
      (message "Keycast ON"))))

;; sudo-edit 更改 文件读写模式
(use-package sudo-edit
  :ensure t)

;; vterm 终端模拟器
(when (or sys/mac-x-p sys/linux-x-p (daemonp))
  (use-package  vterm
        :ensure t
    )

  (use-package multi-vterm
        :ensure t
        :config
        (add-hook 'vterm-mode-hook
                (lambda ()
                    (setq-local evil-insert-state-cursor 'box)
                    (evil-insert-state)))
        (define-key vterm-mode-map [return]                      #'vterm-send-return)

        (setq vterm-keymap-exceptions nil)
        (evil-define-key 'insert vterm-mode-map (kbd "C-e")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-f")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-a")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-v")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-b")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-w")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-u")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-d")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-n")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-m")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-p")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-j")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-k")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-r")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-t")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-c")      #'vterm--self-insert)
        (evil-define-key 'insert vterm-mode-map (kbd "C-SPC")    #'vterm--self-insert)
        (evil-define-key 'normal vterm-mode-map (kbd "C-d")      #'vterm--self-insert)
        (evil-define-key 'normal vterm-mode-map (kbd ",c")       #'multi-vterm)
        (evil-define-key 'normal vterm-mode-map (kbd ",n")       #'multi-vterm-next)
        (evil-define-key 'normal vterm-mode-map (kbd ",p")       #'multi-vterm-prev)
        (evil-define-key 'normal vterm-mode-map (kbd "i")        #'evil-insert-resume)
        (evil-define-key 'normal vterm-mode-map (kbd "o")        #'evil-insert-resume)
        (evil-define-key 'normal vterm-mode-map (kbd "<return>") #'evil-insert-resume))
)

(use-package posframe
    :ensure t
    :defer t)

(use-package markdown-mode
    :ensure t
    :defer t)


;; not use ------ begin ---------
;;从Emacs内部管理外部服务
;; (use-package prodigy
;;   :commands (prodigy)
;;   :defer 1
;;   :config
;;   (progn

;;     ;; define service
;;     (prodigy-define-service
;;       :name "Hugo Server"
;;       :command "hugo"
;;       :args '("server" "-D" "--navigateToChanged" "-t" "even")
;;       :cwd blog-admin-dir
;;       :tags '(hugo server)
;;       :kill-signal 'sigkill
;;       :kill-process-buffer-on-stop t)

;;     (prodigy-define-service
;;       :name "hugo Deploy"
;;       :command "bash"
;;       :args '("./deploy.sh")
;;       :cwd blog-admin-dir
;;       :tags '(hugo deploy)
;;       :kill-signal 'sigkill
;;       :kill-process-buffer-on-stop t)))


;;不了解 separedit
;; (use-package separedit
;;   :ensure t
;;   :init
;;   (define-key prog-mode-map (kbd "C-c '") #'separedit)
;;   (define-key minibuffer-local-map (kbd "C-c '") #'separedit)
;;   (define-key help-mode-map (kbd "C-c '") #'separedit)


;;   ;; Default major-mode for edit buffer
;;   ;; can also be other mode e.g. ‘org-mode’.
;;   (setq separedit-default-mode 'markdown-mode))

;;probuffer
;; (use-package protobuf-mode
;;   :ensure t
;;   :config
;;   (define-key protobuf-mode-map (kbd "RET") 'av/auto-indent-method-maybe))

;; UUID
;; (use-package uuidgen
;;   :ensure t
;;   :commands (uuidgen))

;;
;; (use-package link-hint
;;   :ensure t
;;   :defer t)

;;(setq tramp-adb-program "/Users/lionqu/Library/Android/sdk/platform-tools/adb")
;; not use ------ end ---------

(provide 'init-tools)